//
//  EditTableViewController.m
//  11210
//
//  Created by student on 16/3/7.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "EditTableViewController.h"
#import "BIDPresident.h"
#import "PreDetailTableViewController.h"


@interface EditTableViewController ()<PreDetailTableViewControllerDelegate>
@property(nonatomic,strong)NSMutableArray *list;
@property(nonatomic,strong)NSIndexPath *curSec;
@end

@implementation EditTableViewController

-(NSMutableArray *)list{
    if (_list==nil) {
        _list=[NSMutableArray array];
        NSString *path=[[NSBundle mainBundle]pathForResource:@"Presidents" ofType:@"plist"];
        NSData *data=[NSData dataWithContentsOfFile:path];
        NSKeyedUnarchiver *unar=[[NSKeyedUnarchiver alloc]initForReadingWithData:data];
        NSArray *arr=[unar decodeObjectForKey:@"Presidents"];
        [_list addObjectsFromArray:arr];
    }
    return _list;
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    PreDetailTableViewController *nextVC=segue.destinationViewController;
    nextVC.delegate=self;
    nextVC.pre=self.list[self.curSec.row];
}





- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.list.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    BIDPresident *pre=[BIDPresident new];
    pre=_list[indexPath.row];
    cell.textLabel.text=pre.name;
    cell.detailTextLabel.text=[NSString stringWithFormat:@"%@-%@",pre.fromYear,pre.toYear];
    return cell;
}

-(NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.curSec=indexPath;
    return indexPath;
}

-(void)refresh{
    [self.tableView reloadData];
}

@end
